package com.tanhua.server.controller;

import com.tanhua.model.vo.CountsVo;
import com.tanhua.model.vo.FriendVo;
import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.UserInfoVo;
import com.tanhua.server.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * 用户信息管理 控制层
 */
@RestController
@RequestMapping("/users")
public class UserInfoController {

    @Autowired
    private UserInfoService userInfoService;

    /**
     * 用户信息管理-查询用户资料
     */
    @RequestMapping(method = RequestMethod.GET)
    public ResponseEntity getUserInfo(Long userID){
        UserInfoVo userInfoVo = userInfoService.getUserInfo(userID);
        return ResponseEntity.ok(userInfoVo);
    }



    /**
     * 用户信息管理-更新用户资料
     */
    @RequestMapping(method = RequestMethod.PUT)
    public ResponseEntity updateUserInfo(@RequestBody UserInfoVo userInfoVo){
        userInfoService.updateUserInfo(userInfoVo);
        return ResponseEntity.ok(null);
    }

    //互相喜欢，喜欢，粉丝 - 统计
    @RequestMapping(value = "/counts", method = RequestMethod.GET)
    public ResponseEntity queryCounts() {
        CountsVo countsVo = userInfoService.queryCounts();
        return ResponseEntity.ok(countsVo);
    }

    //互相喜欢，喜欢，粉丝、谁看过我 - 分页查询
    @RequestMapping(value = "/friends/{type}", method = RequestMethod.GET)
    public ResponseEntity queryFriendsByPage(@PathVariable("type") int type,@RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "10") int pagesize) {
        PageResult<FriendVo> pageResult = userInfoService.queryFriendsByPage(type,page,pagesize);
        return ResponseEntity.ok(pageResult);
    }

    //粉丝-喜欢
    @RequestMapping(value = "/fans/{uid}", method = RequestMethod.POST)
    public ResponseEntity makeFriends(@PathVariable("uid") Long friendId) {
        userInfoService.makeFriends(friendId);
        return ResponseEntity.ok(null);
    }

    //喜欢取消
    @DeleteMapping("/like/{uid}")
    public ResponseEntity disLike(@PathVariable("uid") Long friendId){
        userInfoService.disLike(friendId);
        return ResponseEntity.ok(null);
    }

}
